priority 0

extends texmath, ganxCasteltex

global !p
def math():
	return vim.eval('vimtex#syntax#in_mathzone()') == '1'

def comment():
	return vim.eval('vimtex#syntax#in_comment()') == '1'

def env(name):
	[x,y] = vim.eval("vimtex#env#is_inside('" + name + "')")
	return x != '0' and y != '0'

endglobal

snippet today "Date"
`date +%F`
endsnippet

snippet template "Basic template" b
\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[dutch]{babel}
\usepackage{amsmath, amssymb}

\begin{document}
	$0
\end{document}
endsnippet

snippet tpl01 "Basic template" b
\documentclass{ctexart}

\begin{document}
$0
\end{document}
endsnippet


######################################
#  Related to papers written by gxh  #
######################################

# sddsp

snippet ddsp "data-driven stochastic programming #abbreviation by ganx" wA
data-driven stochastic programming $0
endsnippet

snippet SP "stochastic programming #abbreviation by ganx" wA
stochastic programming $0
endsnippet

snippet secsub "Section and subsections by ganx" bA
\section{$1}%
\label{sec:$2}
\subsection{预备知识}%
\label{sub:$2_prerequisites}

$0

\subsection{关键问题}%
\label{sub:$2}



\subsection*{答案}


endsnippet

snippet xe "Set compilor xelatex by ganx" b
%!TEX program = xelatex
%!TEX encoding = UTF-8 Unicode
endsnippet

snippet gls "Glossaries for CN and EN by ganx" bA
\newglossaryentry{$1}{
	name={$2},
	description={\emph{$3}},
	sort={$1}
}
\newglossaryentry{${3/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}{
	name={$3},
	description={\emph{$2}},
	sort={$3}
}$0
endsnippet

snippet gln "Glossaries for notations by ganx" bA
\newglossaryentry{$1}{
	name={$$2$},
	description={\emph{$3}},
	sort={$1}
}$0
endsnippet

snippet eqr "Equation reference by ganx" wA
\eqref{eq:$1}$0
endsnippet

snippet glr "Glossaries reference by ganx" iA
\gls{$1}$0
endsnippet

snippet glg "Glossaries reference by ganx" iA
\gls{$1} (\gls{$2})$0
endsnippet

snippet fah "Link to answers" bA
\begin{hint}\label{hnt:pr:$1}
\end{hint}
\noindent\faHandPointerO ~\hyperlink{target:pr:$1}{前往答案}
\noindent\faHandPointerO ~\hyperref[pr:$1]{返回问题~\ref{pr:$1}}
\hypertarget{target:pr:$1}{}$0
endsnippet

######################################
#  Environment (reserved letter: e)  #
######################################

snippet beg "begin{} / end{} by ganx" bA
\begin{$1}\label{$2}
	${0:${VISUAL}}
\end{$1}
endsnippet

snippet cmnts "begin{commentShow} / end{} by ganx" bA
\begin{commentShow}
	${1:${VISUAL}}
\end{commentShow}$0
endsnippet

snippet cmnt "begin{comment} / end{} by ganx" b
\begin{comment}
	${1:${VISUAL}}
\end{comment}$0
endsnippet

snippet frame "frame environment by ganx"
\begin{frame}[${1:c}]{${2:title}}
	\begin{itemize}[<+- | alert@+>]
		\item ${3:${VISUAL}}
		\item $4
		\item $5
	\end{itemize}
\end{frame}

$0
endsnippet

snippet iframe "iframe environment by ganx"
\begin{iframe}[${1:c}]{${2:title}}
	\begin{itemize}[<+- | alert@+>]
		\item ${3:${VISUAL}}
		\item $4
		\item $5
	\end{itemize}
\end{iframe}

$0
endsnippet

snippet oframe "oframe environment by ganx"
\begin{oframe}[${1:c}]{${2:title}}
	\begin{itemize}[<+- | alert@+>]
		\item ${3:${VISUAL}}
		\item $4
		\item $5
	\end{itemize}
\end{oframe}

$0
endsnippet

snippet hideit "hide text in a beamer presentation by ganx" bA
\hideit{${1:${VISUAL}}}$0
endsnippet

snippet alis "align envionment by ganx short" bA
\begin{align}
	${1:${VISUAL}}
	& ={} $2 \\notag \\\\
	& ={} $3 \\label{eq:$4}.
\end{align}$0
endsnippet

snippet alil "aligned envionment by ganx long" bA
\begin{align}
		& ${1:${VISUAL}}  \\notag \\\\
	= {} & {} $2 \\\\
	= {} & {} $3 \\label{eq:$4}.
\end{align}$0
endsnippet

snippet ali* "align* envionment by ganx" bA
\begin{align*}
	${1:${VISUAL}}
	&= $2 \\\\
	&= $3.
\end{align*}$0
endsnippet

snippet alid "aligned envionment by ganx" bA
\begin{aligned}
	${1:${VISUAL}}
	&= $2 \\\\
	&= $3.
\end{aligned}$0
endsnippet

snippet alid* "aligned* envionment by ganx" bA
\begin{aligned*}
	${1:${VISUAL}}
	&= $2 \\\\
	&= $3.
\end{aligned*}$0
endsnippet

snippet 'eq "Labeled equation environment by ganx" bA
\begin{equation}\label{eq:${1}}
	${0:${VISUAL}}
\end{equation}
endsnippet

snippet 'ml "Labeled multline equation environment by ganx" bA
\begin{multline}\label{eq:${1}}
	${2} \\\\
	${0:${VISUAL}}
\end{multline}
endsnippet

snippet crl "corollary in elegantbook package by ganx" bA
\begin{corollary}[$1]\label{cor:$2}
	$0
\end{corollary}
endsnippet

snippet def "definition in elegantbook package by ganx" bA
\begin{definition}[$1]\label{def:$2}
	$0
\end{definition}
endsnippet

snippet exa "example environment with option and label by ganx" b
\begin{example}\label{ex:${1:}}
	${0:${VISUAL}}
\end{example}
endsnippet

snippet exep "exercise environment with option and label by ganx" bA
\begin{exercise}\label{exe:$1}
	$2
\end{exercise}
\begin{proof}\label{pf:$1}
	$0
\end{proof}
endsnippet

snippet pf "proof environment with label by ganx" bA
\begin{proof}\label{pf:$1}
	$0
\end{proof}
endsnippet

snippet exes "exercise environment with option and label by ganx" bA
\begin{exercise}\label{exe:$1}
	$2
\end{exercise}
\begin{solution}\label{sol:$1}
	$0
\end{solution}
endsnippet

snippet prp "problem environment with option and label by ganx" bA
\begin{problem}[$1]\label{pr:$2}
	$3
\end{problem}
% \begin{hint}\label{hnt:pr:$2}
% \end{hint}
% \noindent\faHandPointerO ~\hyperlink[sol:pr:$2]{前往答案}
% \noindent\faHandPointerO ~\hyperref[pr:$2]{返回问题~\ref{pr:$2}}
% \hypertarget{sol:pr:$2}{}答案
% \begin{proof}\label{pf:pr:$2}
% 	$0
% \end{proof}
endsnippet

snippet prs "problem environment with option and label by ganx" bA
\begin{problem}[$1]\label{pr:$2}
	$3
\end{problem}
% \begin{hint}\label{hnt:pr:$2}
% \end{hint}
% \noindent\faHandPointerO ~\hyperlink{target:pr:$2}{前往答案}
% \noindent\faHandPointerO ~\hyperref[pr:$2]{返回问题~\ref{pr:$2}}
% \hypertarget{target:pr:$2}{}
% \begin{solution}\label{sol:pr:$2}
% 	$0
% \end{solution}
endsnippet

snippet exec "exercise environment with option and label by ganx" b
\begin{exercise}\label{exe:$1}
	$0
\end{exercise}
\begin{cast}\label{cast:$1}
	gVim: \href{media/casts/$1-vim.mp4}{$1-vim.mp4};
	VSCode: \href{media/casts/$1-vscode.mp4}{$1-vscode.mp4}.
\end{cast}
endsnippet

snippet intro "introduction in elegantbook package by ganx" bA
\begin{introduction}[导读]
	\item $1
	\item $0
\end{introduction}
endsnippet

snippet lem "lemma in elegantbook package by ganx" bA
\begin{lemma}[$1]\label{lem:$2}
	$0
\end{lemma}
endsnippet

snippet prop "proposition in elegantbook package by ganx" bA
\begin{proposition}[$1]\label{prop:$2}
	$0
\end{proposition}
endsnippet

snippet note "note environment with option and label by ganx" b
\begin{note}\label{note:${2:}}
	${0:${VISUAL}}
\end{note}
endsnippet

snippet share "share environment with option and label by ganx" b
\begin{share}\label{share:${2:}}
	${0:${VISUAL}}
\end{share}
endsnippet

snippet tip "tip environment with option and label by ganx" b
\begin{tip}\label{tip:${2:}}
	${0:${VISUAL}}
\end{tip}
endsnippet

snippet sol "solution environment with option and label by ganx" b
\begin{solution}\label{sol:${1:}}
	${0:${VISUAL}}
\end{solution}
endsnippet

snippet table "Table environment by ganx" b
\begin{table}[${1:htpb}]
	\centering
	$0
	\caption{${2:caption}}
	\label{tab:${3:label}}
\end{table}
endsnippet

snippet thm "theorem in elegantbook package by ganx" bA
\\begin{theorem}[$1]\label{thm:$2}
	$0
\\end{theorem}
endsnippet

snippet lst "listing environment by ganx" bA
\begin{lstlisting}[escapeinside=\`\`]
${1:${VISUAL}}
\end{lstlisting}
$0
endsnippet

# snippet beg "begin{} / end{}" bA
# \\begin{$1}
# 	$0
# \\end{$1}
# endsnippet

priority 100
snippet ... "ldots" iA
\ldots
endsnippet

# snippet table "Table environment by Castel" b
# \begin{table}[${1:htpb}]
# 	\centering
# 	\caption{${2:caption}}
# 	\label{tab:${3:label}}
# 	\begin{tabular}{${5:c}}
# 	$0${5/((?<=.)c|l|r)|./(?1: & )/g}
# 	\end{tabular}
# \end{table}
# endsnippet
#
snippet fig "Figure environment" b
\begin{figure}[${1:htpb}]
	\centering
	${2:\includegraphics[width=0.9\textwidth]{$3}}
	\caption{${4:$3}}
	\label{fig:${5:${3/\W+/-/g}}}
\end{figure}
endsnippet

snippet enum "Enumerate" bA
\begin{enumerate}
	\item $0
\end{enumerate}
endsnippet

# https://tex.stackexchange.com/questions/54055/using-lower-case-roman-numerals-in-enumerate-lists
# https://tex.stackexchange.com/a/58853/104838
snippet enur "Enumerate roman numbers) by ganx" bA
\begin{enumerate}[label=\roman*)]
	\item $0
\end{enumerate}
endsnippet

snippet item "Itemize" bA
\begin{itemize}
	\item $0
\end{itemize}
endsnippet

snippet desc "Description" b
\begin{description}
	\item[$1] $0
\end{description}
endsnippet

snippet pac "Package" b
\usepackage[${1:options}]{${2:package}}$0
endsnippet

snippet => "implies" Ai
\implies
endsnippet

snippet =< "implied by" Ai
\impliedby
endsnippet

context "math()"
snippet iff "iff" Ai
\iff
endsnippet

# Add ')'
snippet mk "Math revised by ganx" wA
$${1}$`!p
if t[2] and t[2][0] not in [',', '.', '?', '-', ')', ' ']:
	snip.rv = ' '
else:
	snip.rv = ''
`$2
endsnippet

snippet mvk "Math inline by ganx" wA
\\(${1:${VISUAL}}\\)$0
endsnippet

snippet dm "Math" wA
\[
	${1:${VISUAL}}
\] $0
endsnippet

# snippet ali "Align" bA
# \begin{align*}
# 	${1:${VISUAL}}
# \end{align*}
# endsnippet

context "math()"
snippet // "Fraction" iA
\\frac{$1}{$2}$0
endsnippet

snippet / "Fraction" i
\\frac{${VISUAL}}{$1}$0
endsnippet

context "math()"
snippet '((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "symbol frac" wrA
\\frac{`!p snip.rv = match.group(1)`}{$1}$0
endsnippet

priority 1000
context "math()"
snippet '^.*\)/' "() frac" wrA
`!p
stripped = match.string[:-1]
depth = 0
i = len(stripped) - 1
while True:
	if stripped[i] == ')': depth += 1
	if stripped[i] == '(': depth -= 1
	if depth == 0: break;
	i-=1
snip.rv = stripped[0:i] + "\\frac{" + stripped[i+1:-1] + "}"
`{$1}$0
endsnippet

context "math()"
snippet '([A-Za-z])(\d)' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet

context "math()"
snippet '([A-Za-z])_(\d\d)' "auto subscript2" wrA
`!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}
endsnippet


snippet sympy "sympyblock " w
sympy $1 sympy$0
endsnippet

priority 10000
snippet 'sympy(.*)sympy' "sympy" wr
`!p
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()
snip.rv = eval('latex(' + match.group(1).replace('\\', '').replace('^', '**').replace('{', '(').replace('}', ')') + ')')
`
endsnippet

priority 1000
snippet math "mathematicablock" w
math $1 math$0
endsnippet

priority 10000
snippet 'math(.*)math' "math" wr
`!p
import subprocess
code = match.group(1)
code = 'ToString[' + code + ', TeXForm]'
snip.rv = subprocess.check_output(['wolframscript', '-code', code])
`
endsnippet

snippet == "equals" iA
&= $1 \\\\
endsnippet

snippet != "equals" iA
\neq 
endsnippet

context "math()"
snippet ceil "ceil" iA
\left\lceil $1 \right\rceil $0
endsnippet

context "math()"
snippet floor "floor" iA
\left\lfloor $1 \right\rfloor$0
endsnippet

snippet pmat "pmat" iA
\begin{pmatrix} $1 \end{pmatrix}$0
endsnippet

snippet bmat "bmat" iA
\begin{bmatrix} $1 \end{bmatrix}$0
endsnippet

context "math()"
snippet () "left( right)" iA
\left( ${1:${VISUAL}}\right) $0
endsnippet

snippet lr "left( right)" i
\left( ${1:${VISUAL}}\right) $0
endsnippet

snippet lr( "left( right)" i
\left( ${1:${VISUAL}}\right) $0
endsnippet

snippet lr| "left| right|" i
\left| ${1:${VISUAL}}\right| $0
endsnippet

snippet lrv "left| right|" i
\lvert ${1:${VISUAL}}\rvert $0
endsnippet

snippet lr{ "left\{ right\}" i
\left\\{ ${1:${VISUAL}}\right\\} $0
endsnippet

snippet lrb "left\{ right\}" i
\left\\{ ${1:${VISUAL}}\right\\} $0
endsnippet

snippet lr[ "left[ right]" i
\left[ ${1:${VISUAL}}\right] $0
endsnippet

snippet lra "leftangle rightangle" iA
\left<${1:${VISUAL}}\right>$0
endsnippet

context "math()"
snippet conj "conjugate" iA
\overline{$1}$0
endsnippet

# snippet dint "integral by ganx" w
# \int_{${1:-\infty}}^{${2:\infty}} ${3:${VISUAL}}\,{\rm d}$0
# endsnippet

# snippet sum "sum" w
# \sum_{n=${1:0}}^{${3:\infty}} ${4:${VISUAL}} $0
# endsnippet

snippet sum "sum by ganx" w
\sum_{${1:i}=${2:1}}^{${3:n}} ${4:a_n z^n}
endsnippet

snippet taylor "taylor" w
\sum_{${1:k}=${2:0}}^{${3:\infty}} ${4:c_$1} (x-a)^$1 $0
endsnippet

snippet lim "limit" w
\lim_{${1:n} \to ${2:\infty}} 
endsnippet

snippet limsup "limsup" w
\limsup_{${1:n} \to ${2:\infty}} 
endsnippet

snippet prod "product" w
\prod_{${1:n=${2:1}}}^{${3:\infty}} ${4:${VISUAL}} $0
endsnippet

snippet part "d/dx" w
\frac{\partial ${1:V}}{\partial ${2:x}} $0
endsnippet

context "math()"
snippet sq "\sqrt{}" iA
\sqrt{${1:${VISUAL}}} $0
endsnippet

context "math()"
snippet sr "^2" iA
^2
endsnippet

context "math()"
snippet cb "^3" iA
^3
endsnippet

context "math()"
snippet td "to the ... power" iA
^{$1}$0
endsnippet

context "math()"
snippet rd "to the ... power" iA
^{($1)}$0
endsnippet

snippet __ "subscript" iA
_{$1}$0
endsnippet

snippet ooo "\infty" iA
\infty
endsnippet

snippet rij "mrij" i
(${1:x}_${2:n})_{${3:$2}\\in${4:\\N}}$0
endsnippet

snippet <= "leq" iA
\le 
endsnippet

snippet >= "geq" iA
\ge 
endsnippet

context "math()"
snippet EE "exists" iA
\exists 
endsnippet

context "math()"
snippet AA "forall" iA
\forall 
endsnippet

context "math()"
snippet xnn "xn" iA
x_{n}
endsnippet

context "math()"
snippet ynn "yn" iA
y_{n}
endsnippet


context "math()"
snippet xii "xi" iA
x_{i}
endsnippet

context "math()"
snippet yii "yi" iA
y_{i}
endsnippet

context "math()"
snippet xjj "xj" iA
x_{j}
endsnippet

context "math()"
snippet yjj "yj" iA
y_{j}
endsnippet

context "math()"
snippet xp1 "x" iA
x_{n+1}
endsnippet

context "math()"
snippet xmm "x" iA
x_{m}
endsnippet

snippet R0+ "R0+" iA
\\R_0^+
endsnippet

#Formating text: italic, bold, underline, small capital, emphase ..
snippet lsi "lst inline by ganx" iA
\lstinline{${1:${VISUAL:text}}} ${0}
endsnippet

snippet ita "italic text"
\textit{${1:${VISUAL:text}}}${0}
endsnippet
snippet bf "bold face text"
\textbf{${1:${VISUAL:text}}}${0}
endsnippet
snippet bfc "bold face text followed by a space"
\textbf{${1:${VISUAL:text}}}~${0}
endsnippet
snippet under "underline text"
\underline{${1:${VISUAL:text}}}${0}
endsnippet
snippet over "overline text"
\overline{${1:${VISUAL:text}}}${0}
endsnippet
snippet emp "emphasize text"
\emph{${1:${VISUAL:text}}}${0}
endsnippet
snippet sc "small caps text"
\textsc{${1:${VISUAL:text}}}${0}
endsnippet
#Choosing font
snippet sf "sans serife text"
\textsf{${1:${VISUAL:text}}}${0}
endsnippet
snippet rm "roman font text"
\textrm{${1:${VISUAL:text}}}${0}
endsnippet
snippet tt "typewriter (monospace) text"
\texttt{${1:${VISUAL:text}}}${0}
endsnippet

#Math font

context "math()"
snippet 'mcd "mathcal by ganx" iA
\mathcal{D}
endsnippet

context "math()"
snippet 'mcf "mathcal by ganx" iA
\mathcal{F}
endsnippet

context "math()"
snippet 'mcg "mathcal by ganx" iA
\mathcal{G}
endsnippet

context "math()"
snippet 'mch "mathcal by ganx" iA
\mathcal{G}
endsnippet

context "math()"
snippet 'mcx "mathcal by ganx" iA
\mathcal{X}
endsnippet

context "math()"
snippet 'mcy "mathcal by ganx" iA
\mathcal{Y}
endsnippet

context "math()"
snippet mcal "mathfrak by ganx" iA
\mathcal{$1}$0
endsnippet

context "math()"
snippet mrak "mathfrak by ganx" iA
\mathfrak{$1}$0
endsnippet

context "math()"
snippet mbb "mathbb by ganx" iA
\mathbb{$1}$0
endsnippet

context "math()"
snippet ms "mathscr by ganx" iA
\mathscr{$1}$0
endsnippet

snippet plot "Plot" w
\begin{figure}[$1]
	\centering
	\begin{tikzpicture}
		\begin{axis}[
			xmin= ${2:-10}, xmax= ${3:10},
			ymin= ${4:-10}, ymax = ${5:10},
			axis lines = middle,
		]
			\addplot[domain=$2:$3, samples=${6:100}]{$7};
		\end{axis}
	\end{tikzpicture}
	\caption{$8}
	\label{${9:$8}}
\end{figure}
endsnippet

snippet nn "Tikz node" w
\node[$5] (${1/[^0-9a-zA-Z]//g}${2}) ${3:at (${4:0,0}) }{$${1}$};
$0
endsnippet

snippet lll "l" iA
\ell
endsnippet

context "math()"
snippet nabl "nabla" iA
\nabla 
endsnippet

context "math()"
snippet xx "cross" iA
\times 
endsnippet

priority 100
# snippet * "cdot" iA
# \cdot 

context "math()"
snippet mrak "mathfrak by ganx" iA
\mathfrak{$1}$0
endsnippet

context "math()"
snippet mbb "mathbb by ganx" iA
\mathbb{$1}$0
endsnippet

context "math()"
snippet ms "mathscr by ganx" iA
\mathscr{$1}$0
endsnippet

snippet plot "Plot" w
\begin{figure}[$1]
	\centering
	\begin{tikzpicture}
		\begin{axis}[
			xmin= ${2:-10}, xmax= ${3:10},
			ymin= ${4:-10}, ymax = ${5:10},
			axis lines = middle,
		]
			\addplot[domain=$2:$3, samples=${6:100}]{$7};
		\end{axis}
	\end{tikzpicture}
	\caption{$8}
	\label{${9:$8}}
\end{figure}
endsnippet

snippet nn "Tikz node" w
\node[$5] (${1/[^0-9a-zA-Z]//g}${2}) ${3:at (${4:0,0}) }{$${1}$};
$0
endsnippet

snippet lll "l" iA
\ell
endsnippet

context "math()"
snippet nabl "nabla" iA
\nabla 
endsnippet

context "math()"
snippet xx "cross" iA
\times 
endsnippet

priority 100
# snippet * "cdot" iA
# \cdot 
# endsnippet

# priority 200
# snippet '\cdot *' "cdot" iA
# *
# endsnippet

context "math()"
snippet norm "norm" iA
\|$1\|$0
endsnippet

priority 100
context "math()"
snippet '(?<!\\)(sin|cos|arccot|cot|csc|ln|log|exp|star|perp)' "ln" rwA
\\`!p snip.rv = match.group(1)`
endsnippet

priority 200
context "math()"
snippet '(?<!\\)(arcsin|arccos|arctan|arccot|arccsc|arcsec|alpha|beta|delta|exp|epsilon|gamma|lambda|Lambda|mu|omega|Omega|phi|pi|rho|sigma|tau|theta|Theta|varphi|xi|zeta|int)' "ln" rwA
\\`!p snip.rv = match.group(1)`
endsnippet

priority 100
context "math()"
snippet -> "to" iA
\to 
endsnippet

priority 200
context "math()"
snippet <-> "leftrightarrow" iA
\leftrightarrow
endsnippet

context "math()"
snippet !> "mapsto" iA
\mapsto 
endsnippet

context "math()"
snippet invs "inverse" iA
^{-1}
endsnippet

context "math()"
snippet compl "complement" iA
^{c}
endsnippet

context "math()"
snippet \\\ "setminus" iA
\setminus 
endsnippet

snippet >> ">>" iA
\gg
endsnippet

snippet << "<<" iA
\ll
endsnippet

context "math()"
snippet DD "delta" iA
\Delta 
endsnippet

snippet ~~ "~" iA
\sim 
endsnippet

context "math()"
snippet bs "big set with \middle| by ganx" wA
\\left\\{$1 \,\middle|\, $2\\right\\}$0
endsnippet

context "math()"
snippet s| "small set with | by ganx" wA
\\{$1 \mid $2\\}$0
endsnippet

context "math()"
snippet set "set" iA
\\{$1\\}$0
endsnippet

snippet || "mid" iA
 \mid 
endsnippet


context "math()"
snippet cc "subset" Ai
\subset 
endsnippet

snippet notin "not in " iA
\not\in 
endsnippet

context "math()"
snippet inn "in " iA
\in 
endsnippet

snippet NN "n" iA
\N
endsnippet

snippet Nn "cap" iA
\cap 
endsnippet

snippet UU "cup" iA
\cup 
endsnippet

snippet uuu "bigcup" iA
\bigcup_{${1:i \in ${2: I}}} $0
endsnippet

snippet nnn "bigcap" iA
\bigcap_{${1:i \in ${2: I}}} $0
endsnippet

snippet OO "emptyset" iA
\O
endsnippet

snippet RR "real" iA
\R
endsnippet

snippet QQ "Q" iA
\Q
endsnippet

snippet ZZ "Z" iA
\Z
endsnippet

snippet 'sin "三角函数 sin by ganx" iA
$\sin${1:\angle} ${2:ABC}$ $0
endsnippet

snippet 'tri "triangle 三角形 ABC by ganx" iA
$\triangle ${1:ABC}$ $0
endsnippet

snippet <! "normal" iA
\triangleleft 
endsnippet

snippet <> "hokje" iA
\diamond 
endsnippet

snippet x0 "notation x>=0" w
$${1:x}($1\ge0)$
endsnippet

context "math()"
snippet '(?<!i)sts' "text subscript" irA
_\text{$1} $0
endsnippet

context "math()"
snippet tt "text" iA
\text{$1}$0
endsnippet

context "math()"
snippet case "cases by ganx" bA
\begin{cases}
	$1, & ${2:\text{if }} $3, \\\\
	$4, & ${5:\text{if }} $0.
\end{cases}
endsnippet

snippet SI "SI" iA
\SI{$1}{$2}
endsnippet

snippet bigfun "Big function" iA
\begin{align*}
	$1: $2 &\longrightarrow $3 \\\\
	$4 &\longmapsto $1($4) = $0
.\end{align*}
endsnippet

snippet cvec "column vector" iA
\begin{pmatrix} ${1:x}_${2:1}\\\\ \vdots\\\\ $1_${2:n} \end{pmatrix}
endsnippet


# Reserved letter: c, t, g, p.
# Reserved letters:

######################################################
#  Text related auto-expansion (reserved letter: t)  #
######################################################

snippet ckt "chktex ignore by ganx" wA
% chktex $0
endsnippet

snippet tch "teaching notes by ganx" bA
\teach{
	${1:${VISUAL}}
}$0
endsnippet

snippet shu1 "书~\cite{shreve_stochastic_2004} by ganx in sc4f" iA
书~\cite{shreve_stochastic_2004}
endsnippet

snippet shu2 "书~\cite{shreve_stochastic_2008} by ganx in sc4f" iA
书~\cite{shreve_stochastic_2008}
endsnippet

snippet lz "\noindent\textbf{例15~~} by ganx" iA
\noindent\textbf{例$1~~}~$0
endsnippet

snippet dyh "dan yin hao Chinese quote text by ganx" iA
「${1:${VISUAL:text}}」${0}
endsnippet

snippet syh "shuang yin hao Chinese double quote text by ganx" iA
『${1:${VISUAL:text}}』${0}
endsnippet

snippet 'tq "quote text by ganx" iA
\`\`${1:${VISUAL:text}}'' ${0}
endsnippet

#################################
#  math related auto-expansion  #
#################################

context "math()"
snippet 'bf "boldface" iA
\mathbf{${1:${VISUAL}}}${0}
endsnippet

context "math()"
snippet 'bg "boldsymbol for Greek letters" iA
\boldsymbol{${1:${VISUAL}}}${0}
endsnippet

snippet 'mpit "math pi(theta) by ganx" iA
$\pi(\theta)$
endsnippet

snippet 'mx "math x by ganx" iA
$x$
endsnippet

########################################
#  Greek letters (rererved letter: g)  #
########################################
snippet 'ga "alpha by ganx" iA
\alpha
endsnippet

snippet 'gb "beta by ganx" iA
\beta
endsnippet

snippet 'gd "delta by ganx" iA
\delta
endsnippet

snippet 'mgd "delta by ganx" iA
\delta
endsnippet

snippet 'gD "Delta by ganx" iA
\Delta
endsnippet

snippet 'ge "epsilon by ganx" iA
\epsilon
endsnippet

snippet 'gs "sigma by ganx" iA
\sigma
endsnippet

snippet 'gt "theta by ganx" iA
\theta
endsnippet

snippet 'mgt "theta by ganx" wA
$\theta$ 
endsnippet

snippet 'gT "Theta by ganx" iA
\Theta
endsnippet

snippet 'gy "gamma by ganx" iA
\gamma
endsnippet

snippet 'gz "zeta" iA
\zeta
endsnippet

##################################
#  Calculus (reserved letter: c  #
##################################

snippet 'ci "integral by ganx" iA
\int_{${1:0}}^{${2:t}} ${3:${VISUAL}} \mathop{}\!\mathrm{d}{${4:t}}$0
endsnippet

snippet 'dif "dif by ganx" wA
\mathop{}\!\mathrm{d}
endsnippet

#####################################################
#  Probability and Statistics (Reserved letter: p)  #
#####################################################

snippet 'ps "random variable X by ganx" iA
(\Omega, \mathcal{F}, \mathbb{P})
endsnippet

snippet 'mpe "random variable X by ganx" iA
$\mathbb{E}[${1:${VISUAL}}]$$0
endsnippet

snippet 'pne "random variable X by ganx" iA
\widetilde{\mathbb{E}}\left[ ${1:${VISUAL}} \right]$0
endsnippet

snippet 'pe "random variable X by ganx" iA
\mathbb{E}\left[ ${1:${VISUAL}} \right]$0
endsnippet

snippet 'pcf "conditional prob. dist. fun by ganx" iA
f(x|\theta)
endsnippet

snippet 'mpcf "math conditional prob. dist. fun by ganx" wA
$f(x|\theta)$
endsnippet

snippet 'pcF "conditional cumulative dist. fun by ganx" iA
F(x|\theta)
endsnippet

snippet 'mpcF "math conditional cumulative dist. fun by ganx" iA
$F(x|\theta)$
endsnippet

snippet 'mpps "math posterior dist. fun by ganx" iA
$\pi(x|\theta)$
endsnippet

snippet 'pps "posterior dist. fun by ganx" iA
\pi(x|\theta)
endsnippet

snippet 'mbi "binom{}{} by ganx" iA
\binom{${1:n}}{${2:x}}$0
endsnippet

snippet 'mp( "random variable X by ganx" iA
$\mathbb{P}(${1:${VISUAL}})$$0
endsnippet

snippet 'mp{ "random variable X by ganx" iA
$\mathbb{P}\\{${1:${VISUAL}}\\}$$0
endsnippet

snippet 'pnp "random variable X by ganx" iA
\widetilde{\mathbb{P}\left\\{${1:${VISUAL}}\right\\}}$0
endsnippet

snippet 'pp "random variable X by ganx" iA
\mathbb{P}\left[${1:${VISUAL}}\right]$0
endsnippet

snippet 'pbi "Binomial distribution by ganx" iA
\mathscr{B}(n,\theta)
endsnippet

snippet 'pdn "Normal distribution by ganx" iA
\mathscr{N}($1,$2)$0
endsnippet

snippet 'X "random variable X by ganx" iA
$\mathbf{X}$
endsnippet

#########################
#  Terms in math & Stat #
#########################

snippet Bay "Bayesiain analysis by ganx"
Bayesian analysis 
endsnippet

snippet Lik "Likelihood Principle by ganx"
Likelihood Principle 
endsnippet

snippet pos "posterior distribution by ganx"
posterior distribution 
endsnippet

snippet prid "prior distribution by ganx"
prior distribution 
endsnippet

snippet pri "prior information by ganx"
prior information 
endsnippet

snippet Pri "Prior information by ganx"
Prior information 
endsnippet

snippet samp "sample information by ganx"
sample information 
endsnippet

snippet Samp "Sample information by ganx"
Sample information 
endsnippet

snippet suf "sufficient statistic by ganx"
sufficient statistic 
endsnippet

snippet Suf "Sufficient statistic by ganx"
Sufficient statistic 
endsnippet

#################
#  expressions  #
#################

snippet 'am "AP order shceme by ganx" iA
(Z,\hat{x}) 
endsnippet

snippet 'i= "i=1,2,\ldots,n by ganx" iA
${1:i} = 1, 2, \ldots, ${2:N}$0
endsnippet

snippet 'n= "n=1,2,\ldots,n by ganx" iA
${1:n} = 1, 2, \ldots, ${2:N}$0
endsnippet

snippet aln "a_1,a_2,\ldots,a_n by ganx" wA
${1:a}_1,${2:a}_2,\ldots,${3:a}_${4:n}$0
endsnippet

snippet 'kc "$K$-convex by ganx" wA
$K$-convex 
endsnippet

snippet 'ky "$K$-convexity by ganx" wA
$K$-convexity 
endsnippet

snippet 'ly "$L(y)$ by ganx" wA
$L(y)$ 
endsnippet

snippet 'rf "Risk function R(\theta,\delta) by ganx" w
R(\theta,\delta) 
endsnippet

snippet 'mrf "Risk function R(\theta,\delta) by ganx" w
$R(\theta,\delta)$ 
endsnippet

##########
#  Text  #
##########

snippet bc "Color words with blue by ganx" wA
{\footnotesize\color{blue} ${1:${VISUAL}}}$0
endsnippet

snippet gc "Color words with green by ganx" wA
{\footnotesize\color{green} ${1:${VISUAL}}}$0
endsnippet

snippet rc "Color words with red by ganx" wA
{\footnotesize\color{red} ${1:${VISUAL}}}$0
endsnippet

snippet yc "Color words with yellow by ganx" wA
{\footnotesize\color{yellow} ${1:${VISUAL}}}$0
endsnippet

snippet kqts "课前探索 by ganx" wA
课前探索：$0
endsnippet

snippet ksjd "课上解答 by ganx" wA
课上解答：$0
endsnippet

snippet kt "kaiti by ganx" wA
~{\kaiti ${1:${VISUAL}}}~$0
endsnippet

snippet nll "two newlines by ganx" iA
\\\\~\\\\$0
endsnippet

snippet tdnowm "todonote now at margin by ganx" bA
\tdnow[caption=
	\textbf{now by $1:} $2
]{%
	\textbf{now by $1:} $2
}
$0
endsnippet

snippet tdnowin "todonote now inline by ganx" bA
\tdnowin[caption=
	\textbf{now by $1:} $2
]{%
	\begin{minipage}{\linewidth}
	\textbf{Todo now by $1:} $2
		\begin{itemize}
			\item $3
			\item $4
			\item $5
		\end{itemize}
	\end{minipage}
}
$0
endsnippet

snippet tdnextin "todonote next and inline by ganx" bA
\tdnowin[caption=
	\textbf{Todo next by $1:} $2
]{%
	\begin{minipage}{\linewidth}
	\textbf{next by $1:} $2
		\begin{itemize}
			\item $3
			\item $4
			\item $5
		\end{itemize}
	\end{minipage}
}
$0
endsnippet

snippet tdstin "todonote sometime and inline by ganx" bA
\tdstin[caption=
	\textbf{sometime by $1:} $2
]{%
	\begin{minipage}{\linewidth}
	\textbf{Todo sometime by $1:} $2
		\begin{itemize}
			\item $3
			\item $4
			\item $5
		\end{itemize}
	\end{minipage}
}
$0
endsnippet

snippet tdinfoin "todonote improve and inline by ganx" bA
\tdinfoin[caption=
  \textbf{$1:} $2
]{%
\begin{minipage}{\linewidth}
  \textbf{$1:} $2
  \begin{itemize}
    \item $3
    \item $4
    \item $5
  \end{itemize}
\end{minipage}
}
$0
endsnippet

snippet tdipvin "todonote improve and inline by ganx" bA
\tdipvin[caption=
	\textbf{improve by $1:} $2
]{%
	\begin{minipage}{\linewidth}
	\textbf{To improve by $1:} $2
		\begin{itemize}
			\item $3
			\item $4
			\item $5
		\end{itemize}
	\end{minipage}
}
$0
endsnippet

snippet mn "margin note by ganx" wA
\marginpar{${1:${VISUAL}}}$0
endsnippet

snippet ntd "note in beamer by ganx" bA
\note{$1。${2:\\\\~}\\\\}$0
endsnippet

snippet ntq "note of question in beamer by ganx" bA
\note{提问：${1:${VISUAL}}？ \\\\}
\note{\hspace{0.95cm} 提示：$2。${3:\\\\~}\\\\}$0
endsnippet

snippet nte "note of exercise in beamer by ganx" bA
\note{练习：${1:${VISUAL}}。 \\\\}
\note{\hspace{0.95cm} 提示：$2。${3:\\\\~}\\\\}$0
endsnippet

snippet sout "delete text by ganx" wA
\sout{%
${1:${VISUAL}}%
}$0
endsnippet

snippet ul "underline text by ganx" wA
\uline{%
${1:${VISUAL}}%
}$0
endsnippet

snippet uud "underline text double by ganx" wA
\uuline{%
${1:${VISUAL}}%
}$0
endsnippet

snippet uw "uwave text by ganx" wA
\uwave{%
${1:${VISUAL}}%
}$0
endsnippet

priority 10
context "math()"
snippet "bar" "bar" riA
\overline{$1}$0
endsnippet

context "math()"
snippet "vec" "vec 向量 by ganx" riA
\vec{$1}$0
endsnippet

priority 100
context "math()"
snippet "([a-zA-Z])bar" "bar" riA
\overline{`!p snip.rv=match.group(1)`}
endsnippet

context "math()"
snippet "([a-zA-Z])under" "underline" riA
\underline{`!p snip.rv=match.group(1)`}
endsnippet

context "math()"
snippet "([a-zA-Z])vec" "vec" riA
\vec{`!p snip.rv=match.group(1)`}
endsnippet

priority 10

context "math()"
snippet "wdh" "widehat" riA
\widehat{$1}$0
endsnippet

context "math()"
snippet "wdp" "wideparen" riA
\wideparen{$1}$0
endsnippet

context "math()"
snippet "wdt" "widetilde" riA
\widetilde{$1}$0
endsnippet

context "math()"
snippet "hat" "hat" riA
\hat{$1}$0
endsnippet

priority 100
context "math()"
snippet "([a-zA-Z])hat" "hat" riA
\hat{`!p snip.rv=match.group(1)`}
endsnippet

snippet letw "let omega" iA
Let $\Omega \subset \C$ be open.
endsnippet

# mahjong

snippet mhj "print mahjong" iA

\mahjong{$1}

$0
endsnippet

snippet mj "print mahjong" iA
手上的牌如下所示：
\vspace{0.8cm}

\mahjong{$1}

\vspace{0.8cm}

$0
endsnippet


# vim:ft=snippets
